﻿namespace LeetCodeProject._0001_1000._001_100._31_40._036;

public class Solution
{
    public bool IsValidSudoku(char[][] board)
    {
        int[,] rows = new int[9, 9];
        int[,] cols = new int[9, 9];
        int[,,] boxes = new int[3, 3, 9];
        for (int i = 0; i < 9; i++)
        {
            for (int j = 0; j < 9; j++)
            {
                char c = board[i][j];
                if (c != '.')
                {
                    int index = c - '0' - 1;
                    rows[i, index]++;
                    cols[j, index]++;
                    boxes[i / 3, j / 3, index]++;
                    if (rows[i, index] > 1 || cols[j, index] > 1 || boxes[i / 3, j / 3, index] > 1)
                    {
                        return false;
                    }
                }
            }
        }

        return true;
    }
}